---
title: Get page count
summary: Validates a submitted PDF and returns its page count via the iTextSharp-based client service.
status: draft
owner: Not determined from source
last_reviewed: 2026-09-17
library: PdfAPI
reference_type: embedded
operation_id: OP-GET-PAGE-COUNT
trigger: Client submits POST v1/info/pages/count with PDF bytes
---

# OP-GET-PAGE-COUNT: Get page count

Validates that submitted bytes are a real PDF, then returns the page count.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-GET-PAGE-COUNT |
| **Trigger** | Client submits `POST v1/info/pages/count` with PDF bytes |
| **Entry endpoint** | [`POST v1/info/pages/count`](../endpoints/info-controller.md#post-v1%2Finfo%2Fpages%2Fcount) |
| **Owning component** | `InfoController.GetPageCount(byte[])` → `PdfClientService.GetPageCount(byte[])` |
| **Inputs** | Request body: `byte[]` PDF |
| **Outputs** | Bare `int` page count |
| **Failure response** | No `try`/`catch` on this action — any exception produces framework exception detail (`IncludeErrorDetailPolicy.Always`) before `ApiResponseHandler` runs; the final client-visible envelope is unknown** (see [Endpoints: Error response shape](../endpoints.md#error-response-shape)) |

## Steps

1. `PdfClientService.ValidatePdf` checks the `%PDF-` file signature ([BR-PDFAPI-005](../business-rules.md#br-pdfapi-005-pdf-validity-by-file-signature)).
   - On failure: a `PdfException` is thrown reporting that the file is not a valid PDF document (exact message text is not visible in this repository); no `try`/`catch` on this action, so it escapes to the framework, producing exception detail (`IncludeErrorDetailPolicy.Always`) before `ApiResponseHandler` runs; the final client-visible envelope is unknown**.

   This validation is implemented in `PdfAPI.Core` (`PdfClientService.ValidatePdf`/`GetPageCount`), documented in full at [Validate PDF bytes](../../../libraries/pdfapi-core/operations/op-01-validate-pdf-bytes.md) (OP-01) and [Count pages](../../../libraries/pdfapi-core/operations/op-05-count-pages.md) (OP-05); its behavior is summarized here only as observed on this request path.

   > **Origin:** The PDF-signature validation and page-counting behaviors described in this step
   > are implemented in `PdfAPI.Core`, not in `PdfAPI`. See the linked operation pages for the
   > full delegated logic.
2. `PdfClientService.GetPageCount` (iTextSharp-based) reads the page count from the validated document.
3. The bare `int` is returned — HTTP `200`.

## Process flow

The following diagram shows the validation and page-count sequence.

```mermaid
flowchart TD
    A["POST v1/info/pages/count"] --> B["ValidatePdf: check file signature"]
    B -->|Invalid| C["PdfException escapes to framework: 500"]
    B -->|Valid| D["GetPageCount via iTextSharp"]
    D --> E["Return int, 200"]
```

## Transaction and side effects

| Aspect | Finding |
| --- | --- |
| Unit of work | None |
| Commit point | Not applicable — no database access |
| Records written | None |
| Downstream calls | None |
| Repeat-call behavior | Read-only; safe to repeat |

## Logging

| Surface | Written content |
| --- | --- |
| — | No dedicated logging observed on this path beyond framework-level exception logging on an uncaught failure |

## Error handling

- Non-PDF payload: `PdfException` escapes uncaught, producing framework exception detail before `ApiResponseHandler` runs; the final client-visible envelope is unknown** ([BR-PDFAPI-005](../business-rules.md#br-pdfapi-005-pdf-validity-by-file-signature); see [Endpoints: Error response shape](../endpoints.md#error-response-shape)).

## Related documentation
- [API index](../index.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Endpoints](../endpoints.md)
- [Authentication and authorization](../authentication-authorization.md)
- [Dependencies](../dependencies.md)
- [Configuration](../configuration.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Data model](../data-model.md)
- [Operational runbook](../operational-runbook.md)
- [Tech debt](../tech-debt.md)

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- PdfAPI\Controllers\v1\InfoController.cs
- PdfAPI.Core\Services\PdfClientService.cs
